package rootpackege.spring.controller.websocket;

import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
/**
 * 继承AbstractWebSocketHandler类 就可以有选择行的重写websocket通信相关的方法
 * @author BriansPC
 *
 */
public class Basicwebsocket extends AbstractWebSocketHandler{

	@Override
	protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
		
		System.out.println("收到客户端发送过来的文本消息内容："+message);
		
		session.sendMessage(new TextMessage("服务端消息确认"));
	}

	@Override
	public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
		System.out.println("连接成功关闭......");
	}

	@Override
	public void afterConnectionEstablished(WebSocketSession session) throws Exception {
		System.out.println("连接创建成功......");
	}

	
	
//	@Override
//	public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
//		// TODO Auto-generated method stub
//		super.handleMessage(session, message);
//	}
	
}
